package com.example.final_project.Home.frag;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.final_project.Home.adapter.FragAdapter;
import com.example.final_project.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class HomeOutFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home_out, container, false);

//
        TabLayout tab = view.findViewById(R.id.home_TL);
        ViewPager homekids = view.findViewById(R.id.kidfrag_position);
        tab.setupWithViewPager(homekids);

        //设置标题名称
        List<String> tab_name = new ArrayList<>();
        tab_name.add("推荐");
        tab_name.add("资讯");

        //创建FragmentStatePagerAdapter适配器---可以装载Fragment
        List<Fragment> frags = new ArrayList<>();
        frags.add(new HomeFragment());
        frags.add(new PlayCarFragment());

        FragmentManager fragmentManager = getChildFragmentManager();
        FragAdapter fragAdapter = new FragAdapter(fragmentManager,frags,tab_name);
        homekids.setAdapter(fragAdapter);

        return view;
    }
}